package com.nuoyuan.wx.admin.controller;

import com.nuoyuan.wx.common.controller.BaseController;
import com.nuoyuan.wx.vo.PageVo;
import com.nuoyuan.wx.vo.UserVo;
import com.nuoyuan.wx.common.dto.BaseRespDto;
import com.nuoyuan.wx.common.utils.GsonUtil;
import com.nuoyuan.wx.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Package com.nuoyuan.wx.admin.controller
 * @ClassName UserController
 * @Description TODO
 * @Author linus
 * @Date 2020-02-13 14:19
 * @Version 1.0
 **/
@RestController("AdminUserController")
public class UserController extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private UserService userService;
    /**
     * 列表
     * @param page
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/admin/users", method = RequestMethod.GET)
    @ResponseBody
    public String list(PageVo page, HttpServletRequest request, HttpServletResponse response) {
        BaseRespDto<PageVo<UserVo>> resp = userService.getList(page);
        if(!resp.isSuccess()) {
            log.error(resp.getMsg());
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            return this.buildErrorResp(resp.getMsg());
        }
        return GsonUtil.toJson(resp.getData());
    }

}
